//
//  SecurityGuardRecordTableViewCell.m
//  PropertyManager
//
//  Created by TNG on 2018/8/9.
//  Copyright © 2018年 Tng. All rights reserved.
//

#import "SecurityGuardRecordTableViewCell.h"

@implementation SecurityGuardRecordTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

-(instancetype) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self creatUI];
        self.backgroundColor = SFM242;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}

-(void)creatUI{
    [self.contentView addSubview:self.bgView];
    [self.bgView addSubview:self.timeLabel];
    [self.bgView addSubview:self.lineView];
    [self.bgView addSubview:self.addressLabel];
    [self.bgView addSubview:self.certifyLabel];
//    [self.bgView addSubview:self.numLabel];
    [self.bgView addSubview:self.personLabel];
}

-(UIView *)bgView
{
    if (_bgView == nil) {
        _bgView = [[UIView alloc] initWithFrame:CGRectMake(15, 0, WIDTH - 30, 140)];
        _bgView.backgroundColor = SFMWhiteColor;
        _bgView.layer.cornerRadius = 4;
        _bgView.clipsToBounds = YES;
    }
    return _bgView;
}

-(UILabel *)timeLabel
{
    if (_timeLabel == nil) {
        _timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 12, WIDTH - 30, 21)];
        _timeLabel.font = font(12);
        _timeLabel.textColor = SFM51;
        _timeLabel.textAlignment = NSTextAlignmentLeft;
    }
    return _timeLabel;
}

-(UILabel *)addressLabel
{
    if (_addressLabel == nil) {
        _addressLabel = [[UILabel alloc] init];
        _addressLabel.font = font(18);
        _addressLabel.textColor = SFM51;
        _addressLabel.textAlignment = NSTextAlignmentLeft;
    }
    return _addressLabel;
}

-(UILabel *)certifyLabel
{
    if (_certifyLabel == nil) {
        _certifyLabel = [[UILabel alloc] init];
        _certifyLabel.font = font(12);
        _certifyLabel.textColor = SFMColor(246, 123, 43);
        _certifyLabel.textAlignment = NSTextAlignmentCenter;
        _certifyLabel.layer.cornerRadius = 10;
        _certifyLabel.layer.borderColor = SFMColor(246, 123, 43).CGColor;
        _certifyLabel.layer.borderWidth = 1;
        _certifyLabel.clipsToBounds = YES;
    }
    return _certifyLabel;
}

//-(UILabel *)numLabel
//{
//    if (_numLabel == nil) {
//        _numLabel = [[UILabel alloc] initWithFrame:CGRectMake(WIDTH - 135, 66, 90, 20)];
//        _numLabel.font = font(12);
//        _numLabel.textColor = SFM153;
//        _numLabel.textAlignment = NSTextAlignmentRight;
//    }
//    return _numLabel;
//}

-(UIView *)lineView
{
    if (_lineView == nil) {
        _lineView = [[UIView alloc] initWithFrame:CGRectMake(15, 40, WIDTH-60, 0.5)];
        _lineView.backgroundColor = SFMLineColor;
    }
    return _lineView;
}

-(UILabel *)personLabel
{
    if (_personLabel == nil) {
        _personLabel= [[UILabel alloc] initWithFrame:CGRectMake(15, 96, WIDTH - 30, 20)];
        _personLabel.font = font(14);
        _personLabel.textColor = SFM153;
        _personLabel.textAlignment = NSTextAlignmentLeft;
    }
    return _personLabel;
}

-(void)send
{
    self.timeLabel.text = @"检查时间：2017-03-12 9:00";
    
    NSString * addressStr = @"A栋6楼电梯口";
    CGFloat addressWidth = [addressStr widthWithFont:font(18) constrainedToHeight:21];
    if (addressWidth > WIDTH - 170) {
        addressWidth = WIDTH - 170;
    }
    self.addressLabel.frame = CGRectMake(15, 66, addressWidth, 21);
    self.addressLabel.text = addressStr;
    
    self.certifyLabel.frame = CGRectMake(CGRectGetMaxX(self.addressLabel.frame) + 10, 66.5, 40, 20);
    self.certifyLabel.text = @"已检";
    
//    self.numLabel.text = @"GH1298567890";
    self.personLabel.text = @"监察人：张三 ｜13456789012";
}

-(void)sendSecurutyGuardRecordModel:(SecurutyGuardRecordModel *)model
{
    self.timeLabel.text = [NSString stringWithFormat:@"检查时间：%@",model.patroltime];
    
    NSString * addressStr = model.patrolarea;
    CGFloat addressWidth = [addressStr widthWithFont:font(18) constrainedToHeight:21];
    if (addressWidth > WIDTH - 170) {
        addressWidth = WIDTH - 170;
    }
    self.addressLabel.frame = CGRectMake(15, 66, addressWidth, 21);
    self.addressLabel.text = addressStr;
    
    self.certifyLabel.frame = CGRectMake(CGRectGetMaxX(self.addressLabel.frame) + 10, 66.5, 40, 20);
    self.certifyLabel.text = @"已检";
    
//    self.numLabel.text = @"GH1298567890";
    self.personLabel.text = [NSString stringWithFormat:@"监察人：%@ ｜%@",model.workname,model.workphonenum];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
